package com.owc.controller.admin;

import com.owc.domain.BaseResult;
import com.owc.domain.PageVo;
import com.owc.domain.dto.admin.VersionDTO;
import com.owc.domain.vo.admin.VersionVo;
import com.owc.service.admin.VersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author Jackies
 * @Date 2019/12/18 22:44
 * @Description TODO://
 **/
@RestController
@RequestMapping(value = "/admin/version")
public class VersionController {

    @Autowired
    private VersionService versionService;

    @PostMapping(value = "add")
    public BaseResult<Boolean> add(@RequestBody @Valid VersionVo versionVo){
        return BaseResult.success(versionService.addVersion(versionVo));
    }

    @PostMapping(value = "list")
    public BaseResult<List<VersionDTO>> list(@RequestBody PageVo pageVo){
        return versionService.list(pageVo);
    }

    @PostMapping(value = "detail")
    public BaseResult<VersionDTO> detail(@RequestBody VersionVo versionVo){
        Assert.notNull(versionVo.getId(),"版本id不能为空");
        return BaseResult.success(versionService.detail(versionVo.getId()));
    }

}
